Skip to content

fix(cache): respect zero ttl#4126

Open
Flo0806 wants to merge 1 commit intonitrojs:mainfrom
Flo0806:fix/respect-zero-ttl
Open

fix(cache): respect zero ttl#4126
Flo0806 wants to merge 1 commit intonitrojs:mainfrom
Flo0806:fix/respect-zero-ttl

Conversation

@Flo0806
Copy link

@Flo0806 Flo0806 commented Mar 18, 2026

🔗 Linked issue

Fixes: #4125
Fixes: nuxt/nuxt#34307

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

swr: 0 set in nuxt.config.ts (see linked issue to Nuxt) it should be handled like max-age=0 - but it will be ignored, because Nitro checks if (swr) what is false with 0, too.
This fix checks explicitly for 0.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@Flo0806 Flo0806 requested a review from pi0 as a code owner March 18, 2026 12:52
@vercel
Copy link

vercel bot commented Mar 18, 2026

@Flo0806 is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

📝 Walkthrough

Walkthrough

Modified SWR cache handling in route rules resolver to distinguish zero values from other falsy values. The swr: 0 configuration now correctly enables caching with maxAge=0 for explicit no-caching behavior, rather than being ignored. A comment documenting the behavior change was added.

Changes

Cohort / File(s) Summary
SWR Cache Handling
src/config/resolvers/route-rules.ts
Updated normalizeRouteRules to treat non-null and non-false SWR values (including zero) as enabling cache. Changed condition to explicitly check for null/false instead of relying on truthiness, allowing swr: 0 to set maxAge=0 for explicit no-caching.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(cache): respect zero ttl' follows conventional commits format with type 'fix' and scope 'cache', clearly summarizing the main change.
Description check ✅ Passed The description explains the bug fix, linked issues, and the problem with swr: 0 being treated as falsy, directly relating to the code changes.
Linked Issues check ✅ Passed The code changes directly address the objectives in issues #4125 and #34307 by explicitly checking for 0 to treat swr: 0 the same as max-age=0.
Out of Scope Changes check ✅ Passed The changes in route-rules.ts are scoped to fixing the swr: 0 handling issue; no out-of-scope modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Flo0806 Flo0806 mentioned this pull request Mar 18, 2026
2 tasks
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/config/resolvers/route-rules.ts (1)

52-52: Remove the explanatory inline comment to match repo style.

Please drop this new comment and keep the logic self-descriptive through code alone.

As per coding guidelines: "Do not add comments explaining what the line does unless prompted".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/config/resolvers/route-rules.ts` at line 52, Remove the inline
explanatory comment "// Cache: swr - allow `swr: 0` to set maxAge=0 (no cache)"
so the code follows repo style; leave the logic that handles the swr/maxAge
behavior intact (wherever swr and maxAge are used in this module, e.g., handling
swr: 0 -> maxAge = 0) but drop the comment so the implementation is
self-descriptive.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/config/resolvers/route-rules.ts`:
- Line 52: Remove the inline explanatory comment "// Cache: swr - allow `swr: 0`
to set maxAge=0 (no cache)" so the code follows repo style; leave the logic that
handles the swr/maxAge behavior intact (wherever swr and maxAge are used in this
module, e.g., handling swr: 0 -> maxAge = 0) but drop the comment so the
implementation is self-descriptive.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 056b06b6-caf5-44a4-868a-90ad46de3297

📥 Commits

Reviewing files that changed from the base of the PR and between 5d51b7f and 4dc0840.

📒 Files selected for processing (1)
  • src/config/resolvers/route-rules.ts

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 18, 2026

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4126

commit: 4dc0840

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SWR should accept 0 Payload is not generated with swr: 0

1 participant